[FIX] cherry-pick 6ff4756c4413698f3d67ae7ef5c650c1cff5a57f
[platform/core/system/swap-probe.git] / probe_socket / libdasocket.c
1 /*
2  *  DA probe
3  *
4  * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: 
7  *
8  * Jaewon Lim <jaewon81.lim@samsung.com>
9  * Woojin Jung <woojin2.jung@samsung.com>
10  * Juyoung Kim <j0.kim@samsung.com>
11  * Anastasia Lyupa <a.lyupa@samsung.com>
12  * 
13  * This library is free software; you can redistribute it and/or modify it under
14  * the terms of the GNU Lesser General Public License as published by the
15  * Free Software Foundation; either version 2.1 of the License, or (at your option)
16  * any later version.
17  * 
18  * This library is distributed in the hope that it will be useful, but WITHOUT ANY
19  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
21  * License for more details.
22  *
23  * You should have received a copy of the GNU Lesser General Public License
24  * along with this library; if not, write to the Free Software Foundation, Inc., 51
25  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26  *
27  * Contributors:
28  * - S-Core Co., Ltd
29  * - Samsung RnD Institute Russia
30  * 
31  */
32
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <dlfcn.h>
37 #include <stdbool.h>
38
39 #include <sys/types.h>
40 #include <sys/socket.h>
41 #include <netdb.h>
42 #include <ifaddrs.h>
43 #include <arpa/inet.h>
44
45 #include <errno.h>
46 #include "daprobe.h"
47 #include "probeinfo.h"
48 #include "dautil.h"
49 #include "dahelper.h"
50 #include "da_socket.h"
51
52
53 #include "binproto.h"
54
55 #define GCC_VERSION (__GNUC__ * 10000 \
56                 + __GNUC__MINOR__ * 100 \
57                 + __GNUC_PATCHLEVEL__ )
58
59
60 static enum DaOptions _sopt = OPT_FILE;
61
62 int socket(int domain, int type, int protocol)
63 {
64         static int (*socketp)(int domain, int type, int protocol);
65         
66         BEFORE_ORIGINAL_NOFILTER(socket, LIBC);
67
68         ret = socketp(domain, type, protocol);
69
70         AFTER_PACK_ORIGINAL_SOCK(API_ID_socket,
71                                  ret, 0, ret, FD_API_OPEN, "ddd", domain, type, protocol);
72
73         return ret;
74 }
75
76 int socketpair(int domain, int type, int protocol,int socket_vector[2])
77 {
78         static int (*socketpairp)(int domain, int type, int protocol,int socket_vector[2]);
79         
80         BEFORE_ORIGINAL_NOFILTER(socketpair, LIBC);
81         
82         ret = socketpairp(domain, type, protocol, socket_vector);
83
84         //TODO: socket pair: socket_vector[0]/socket_vector[1], FD - ?
85         AFTER_PACK_ORIGINAL_SOCK(API_ID_socketpair,
86                                  ret, 0, socket_vector[0], FD_API_OPEN, 
87                                  "dddp", domain, type, protocol, socket_vector);
88         
89         return ret;
90 }
91
92 int shutdown(int socket, int how)
93 {
94         static int (*shutdownp)(int socket, int how);
95         
96         BEFORE_ORIGINAL_NOFILTER(shutdown, LIBC);
97         
98         ret = shutdownp(socket, how);
99
100         AFTER_PACK_ORIGINAL_SOCK(API_ID_shutdown,
101                                  ret, 0, socket, FD_API_OTHER, "dd", socket, how);
102
103         return ret;
104 }
105
106 int bind(int socket, const struct sockaddr *address, socklen_t address_len)
107 {
108         static int (*bindp)(int socket, const struct sockaddr *address, socklen_t address_len);
109         
110         BEFORE_ORIGINAL(bind, LIBC);
111         
112         ret = bindp(socket, address, address_len);
113
114         AFTER_PACK_ORIGINAL_SOCK(API_ID_bind,
115                                  ret, 0, socket, FD_API_MANAGE,
116                                  "dpd", socket, address, address_len);
117         
118         return ret;
119 }
120
121 int listen(int socket, int backlog)
122 {
123         static int (*listenp)(int socket, int backlog);
124         
125         BEFORE_ORIGINAL(listen, LIBC);
126         
127         ret = listenp(socket, backlog);
128
129         AFTER_PACK_ORIGINAL_SOCK(API_ID_listen,
130                                  ret, 0, socket, FD_API_MANAGE, "dd", socket, backlog);
131
132         return ret;
133 }
134
135 int accept(int socket, struct sockaddr *address, socklen_t *address_len)
136 {
137         static int (*acceptp)(int socket, struct sockaddr *address, socklen_t *address_len);
138         
139         BEFORE_ORIGINAL_NOFILTER(accept, LIBC);
140         
141         ret = acceptp(socket, address, address_len);
142
143         AFTER_PACK_ORIGINAL_SOCK(API_ID_accept,
144                                  ret, 0, socket, FD_API_MANAGE,
145                                  "dpp", socket, address, address_len);
146         
147         return ret;
148 }
149
150 int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags)
151 {
152         static int (*accept4p)(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags);
153         
154         BEFORE_ORIGINAL_NOFILTER(accept4, LIBC);
155         
156         ret = accept4p(sockfd, addr, addrlen, flags);
157
158         AFTER_PACK_ORIGINAL_SOCK(API_ID_accept4,
159                                  ret, 0, sockfd, FD_API_MANAGE,
160                                  "dppd", sockfd, addr, addrlen, flags);
161
162         return ret;
163 }
164
165 int connect(int socket, const struct sockaddr *address, socklen_t address_len)
166 {
167         static int (*connectp)(int socket, const struct sockaddr *address, socklen_t address_len);
168         
169         BEFORE_ORIGINAL(connect, LIBC);
170         
171         ret = connectp(socket, address, address_len);
172
173         AFTER_PACK_ORIGINAL_SOCK(API_ID_connect,
174                                  ret, address_len, socket, FD_API_MANAGE,
175                                  "dpd", socket, address, address_len);
176         
177         return ret;
178 }
179
180 int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
181 {
182         static int (*selectp)(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
183         
184         BEFORE_ORIGINAL(select, LIBC);
185         
186         ret = selectp(nfds, readfds, writefds,exceptfds, timeout);
187
188         AFTER_PACK_ORIGINAL_SOCK(API_ID_select,
189                                  ret, 0, nfds, FD_API_MANAGE,
190                                  "dpppp", nfds, readfds, writefds, exceptfds, timeout);
191                         
192         return ret;
193 }
194
195 int pselect(int nfds, fd_set *readfds, fd_set *writefds,fd_set *exceptfds, const struct timespec *ntimeout, const sigset_t *sigmask)
196 {
197         static int (*pselectp)(int nfds, fd_set *readfds, fd_set *writefds,fd_set *exceptfds, const struct timespec *ntimeout, const sigset_t *sigmask);
198
199         BEFORE_ORIGINAL(pselect, LIBC);
200         
201         ret = pselectp(nfds, readfds, writefds,exceptfds, ntimeout, sigmask);
202
203         AFTER_PACK_ORIGINAL_SOCK(API_ID_pselect,
204                                  ret, 0, nfds, FD_API_MANAGE,   "dppppp",
205                                  nfds, readfds, writefds, exceptfds, ntimeout, sigmask);
206  
207         return ret;
208 }
209
210 ssize_t send(int socket, const void *message, size_t length, int flags)
211 {
212         static ssize_t (*sendp)(int socket, const void *message, size_t length, int flags);
213         ssize_t sret;
214  
215         BEFORE_ORIGINAL(send, LIBC);
216         
217         sret = sendp(socket, message, length, flags);
218
219         AFTER_PACK_ORIGINAL_SOCK(API_ID_send,
220                                  sret, sret, socket, FD_API_SEND,
221                                  "dpxd", socket, message, length, flags);
222         
223         return sret;
224 }
225
226 ssize_t sendmsg(int socket, const struct msghdr *message, int flags)
227 {
228         static ssize_t (*sendmsgp)(int socket, const struct msghdr *message, int flags);
229         ssize_t sret;
230  
231         BEFORE_ORIGINAL(sendmsg, LIBC);
232         
233         sret = sendmsgp(socket, message, flags);
234
235         AFTER_PACK_ORIGINAL_SOCK(API_ID_sendmsg,
236                                  sret, sret, socket, FD_API_SEND,
237                                  "dpd", socket, message, flags);
238  
239         return sret;
240 }
241
242 ssize_t sendto(int socket, const void *message, size_t length, int flags,const struct sockaddr *dest_addr, socklen_t dest_len)
243 {
244         static ssize_t (*sendtop)(int socket, const void *message, size_t length, int flags,const struct sockaddr *dest_addr, socklen_t dest_len);
245         ssize_t sret;
246  
247         BEFORE_ORIGINAL(sendto, LIBC);
248         
249         sret = sendtop(socket, message, length, flags, dest_addr, dest_len);
250
251         AFTER_PACK_ORIGINAL_SOCK(API_ID_sendto,
252                                  sret, sret, socket, FD_API_SEND,
253                                  "dpxdpd", socket, message, length, flags, dest_addr, dest_len);
254  
255         return sret;
256 }
257
258 ssize_t recv(int socket, void *buffer, size_t length, int flags)
259 {
260         static ssize_t (*recvp)(int socket, void *buffer, size_t length, int flags);
261         ssize_t sret;
262  
263         BEFORE_ORIGINAL(recv, LIBC);
264
265         sret = recvp(socket, buffer, length, flags);
266
267         AFTER_PACK_ORIGINAL_SOCK(API_ID_recv,
268                                  sret, sret, socket, FD_API_RECEIVE,
269                                  "dpxd", socket, buffer, length, flags);
270         
271         return sret;
272 }
273
274 ssize_t recvfrom(int socket, void *buffer, size_t length, int flags, struct sockaddr *address, socklen_t *address_len)
275 {
276         static ssize_t (*recvfromp)(int socket, void *buffer, size_t length, int flags, struct sockaddr *address, socklen_t *address_len);
277         ssize_t sret;
278
279         BEFORE_ORIGINAL(recvfrom, LIBC);
280         
281         sret = recvfromp(socket, buffer, length, flags, address, address_len);
282
283         AFTER_PACK_ORIGINAL_SOCK(API_ID_recvfrom,
284                                  sret, sret, socket, FD_API_RECEIVE,
285                                  "dpxdpp", socket, buffer, length, flags, address, address_len);
286
287         return sret;
288 }
289
290 ssize_t recvmsg(int socket, struct msghdr *message, int flags)
291 {
292         static ssize_t (*recvmsgp)(int socket, struct msghdr *message, int flags);
293         ssize_t sret;
294  
295         BEFORE_ORIGINAL(recvmsg, LIBC);
296         
297         sret = recvmsgp(socket, message, flags);
298
299         AFTER_PACK_ORIGINAL_SOCK(API_ID_recvmsg,
300                                  sret, sret, socket, FD_API_RECEIVE,
301                                  "dpd", socket, message, flags);
302
303         return sret;
304 }
305
306 uint32_t htonl(uint32_t hostlong)
307 {
308         static uint32_t (*htonlp)(uint32_t hostlong);
309         uint32_t uret;
310  
311         BEFORE_ORIGINAL(htonl, LIBC);
312         
313         uret = htonlp(hostlong);
314
315         AFTER_PACK_ORIGINAL_SOCK(API_ID_htonl,
316                                  uret, 0, 0, FD_API_OTHER, "d", hostlong); 
317  
318         return uret;
319 }
320
321 uint16_t htons(uint16_t hostshort)
322 {
323         static uint16_t (*htonsp)(uint16_t hostshort);
324         uint16_t uret;
325  
326         BEFORE_ORIGINAL(htons, LIBC);
327         
328         uret = htonsp(hostshort);
329
330         AFTER_PACK_ORIGINAL_SOCK(API_ID_htons,
331                                  uret, 0, 0, FD_API_OTHER, "d", hostshort); 
332  
333         return uret;
334 }
335
336 uint32_t ntohl(uint32_t netlong)
337 {
338         static uint32_t (*ntohlp)(uint32_t netlong);
339         uint32_t uret;
340  
341         BEFORE_ORIGINAL(ntohl, LIBC);
342         
343         uret = ntohlp(netlong);
344
345         AFTER_PACK_ORIGINAL_SOCK(API_ID_ntohl,
346                                  uret, 0, 0, FD_API_OTHER, "d", netlong); 
347
348         return uret;
349 }
350
351 uint16_t ntohs(uint16_t netshort)
352 {
353         static uint16_t (*ntohsp)(uint16_t netshort);
354         uint16_t uret;
355  
356         BEFORE_ORIGINAL(ntohs, LIBC);
357         
358         uret = ntohsp(netshort);
359
360         AFTER_PACK_ORIGINAL_SOCK(API_ID_ntohs,
361                                  uret, 0, 0, FD_API_OTHER, "d", netshort); 
362
363         return uret;
364 }
365
366 #if 0
367 uint16_t htobe16(uint16_t host_16bits)
368 {
369         static uint16_t (*htobe16p)(uint16_t host_16bits);
370         uint16_t uret;
371  
372         BEFORE_ORIGINAL(htobe16, LIBC);
373         
374         uret = htobe16p(host_16bits);
375  
376         AFTER_PACK_ORIGINAL_SOCK(uret, 0, 0, FD_API_OTHER, "d", host_16bits); 
377
378         return uret;
379 }
380
381 uint16_t htole16(uint16_t host_16bits)
382 {
383         static uint16_t (*htole16p)(uint16_t host_16bits);
384         uint16_t uret;
385  
386         BEFORE_ORIGINAL(htole16, LIBC);
387         
388         uret = htole16p(host_16bits);
389  
390         AFTER_PACK_ORIGINAL_SOCK(uret, 0, 0, FD_API_OTHER, "d", host_16bits);
391
392         return uret;
393 }
394
395 uint16_t be16toh(uint16_t big_endian_16bits)
396 {
397         static uint16_t (*be16tohp)(uint16_t big_endian_16bits);
398         uint16_t uret;
399  
400         BEFORE_ORIGINAL(be16toh, LIBC);
401         
402         uret = be16tohp(big_endian_16bits);
403
404         AFTER_PACK_ORIGINAL_SOCK(uret, 0, 0, FD_API_OTHER, "d", big_endian_16bits); 
405  
406         return uret;
407 }
408
409 uint16_t le16toh(uint16_t little_endian_16bits)
410 {
411         static uint16_t (*le16tohp)(uint16_t little_endian_16bits);
412         uint16_t uret;
413  
414         BEFORE_ORIGINAL(le16toh, LIBC);
415         
416         uret = le16tohp(little_endian_16bits);
417
418         AFTER_PACK_ORIGINAL_SOCK(uret, 0, 0, FD_API_OTHER, "d", little_endian_16bits); 
419  
420         return uret;
421 }
422
423 uint32_t htobe32(uint32_t host_32bits)
424 {
425         static uint32_t (*htobe32p)(uint32_t host_32bits);
426         uint32_t uret;
427  
428         BEFORE_ORIGINAL(htobe32, LIBC);
429
430         uret = htobe32p(host_32bits);
431
432         AFTER_PACK_ORIGINAL_SOCK(uret, 0, 0, FD_API_OTHER, "d", host_32bits); 
433
434         return uret;
435 }
436
437 uint32_t htole32(uint32_t host_32bits)
438 {
439         static uint32_t (*htole32p)(uint32_t host_32bits);
440         uint32_t uret;
441  
442         BEFORE_ORIGINAL(htole32, LIBC);
443
444         uret = htole32p(host_32bits);
445
446         AFTER_PACK_ORIGINAL_SOCK(uret, 0, 0, FD_API_OTHER, "d", host_32bits); 
447
448         return uret;
449 }
450
451 uint32_t be32toh(uint32_t big_endian_32bits)
452 {
453         static uint32_t (*be32tohp)(uint32_t big_endian_32bits);
454         uint32_t uret;
455  
456         BEFORE_ORIGINAL(be32toh, LIBC);
457
458         uret = be32tohp(big_endian_32bits);
459
460         AFTER_PACK_ORIGINAL_SOCK(uret, 0, 0, FD_API_OTHER, "d", big_endian_32bits); 
461
462         return uret;
463 }
464
465 uint32_t le32toh(uint32_t little_endian_32bits)
466 {
467         static uint32_t (*le32tohp)(uint32_t little_endian_32bits);
468         uint32_t uret;
469  
470         BEFORE_ORIGINAL(le32toh, LIBC);
471
472         uret = le32tohp(little_endian_32bits);
473
474         AFTER_PACK_ORIGINAL_SOCK(API_ID_le32toh,
475                                  uret, 0, 0, FD_API_OTHER, "d", little_endian_32bits); 
476
477         return uret;
478 }
479
480 uint64_t htobe64(uint64_t host_64bits)
481 {
482         static uint64_t (*htobe64p)(uint64_t host_64bits);
483         uint64_t uret;
484
485         BEFORE_ORIGINAL(htobe64, LIBC);
486
487         uret = htobe64p(host_64bits);
488  
489         AFTER_PACK_ORIGINAL_SOCK(uret, 0, 0, FD_API_OTHER, "x", host_64bits); 
490
491         return uret;
492 }
493
494 uint64_t htole64(uint64_t host_64bits)
495 {
496         static uint64_t (*htole64p)(uint64_t host_64bits);
497         uint64_t uret;
498  
499         BEFORE_ORIGINAL(htole64, LIBC);
500
501         uret = htole64p(host_64bits);
502
503         AFTER_PACK_ORIGINAL_SOCK(uret, 0, 0, FD_API_OTHER, "x", host_64bits); 
504
505         return uret;
506 }
507
508 uint64_t be64toh(uint64_t big_endian_64bits)
509 {
510         static uint64_t (*be64tohp)(uint64_t big_endian_64bits);
511         uint64_t uret;
512  
513         BEFORE_ORIGINAL(be64toh, LIBC);
514
515         uret = be64tohp(big_endian_64bits);
516
517         AFTER_PACK_ORIGINAL_SOCK(uret, 0, 0, FD_API_OTHER, "x", big_endian_64bits); 
518
519         return uret;
520 }
521
522 uint64_t le64toh(uint64_t little_endian_64bits)
523 {
524         static uint64_t (*le64tohp)(uint64_t little_endian_64bits);
525         uint64_t uret;
526  
527         BEFORE_ORIGINAL(le64toh, LIBC);
528
529         uret = le64tohp(little_endian_64bits);
530
531         AFTER_PACK_ORIGINAL_SOCK(API_ID_le64toh,
532                                  uret, 0, 0, FD_API_OTHER, "x", little_endian_64bits); 
533
534         return uret;
535 }
536 #endif
537
538 #if 1
539 int inet_aton(const char *cp, struct in_addr *inp)
540 {
541         static int (*inet_atonp)(const char *cp, struct in_addr *inp);
542
543         BEFORE_ORIGINAL(inet_aton, LIBC);
544         
545         ret = inet_atonp(cp,inp);
546
547         AFTER_PACK_ORIGINAL_SOCK(API_ID_inet_aton,
548                                  ret, 0, 0, FD_API_OTHER, "pp", cp, inp);
549  
550         return ret;
551 }
552
553 in_addr_t inet_addr(const char *cp)
554 {
555         static in_addr_t (*inet_addrp)(const char *cp);
556         in_addr_t iret;
557  
558         BEFORE_ORIGINAL(inet_addr, LIBC);
559  
560         iret = inet_addrp(cp);
561
562         AFTER_PACK_ORIGINAL_SOCK(API_ID_inet_addr,
563                                  iret, 0, 0, FD_API_OTHER, "p", cp);
564         
565         return iret;
566 }
567
568 in_addr_t inet_network(const char *cp)
569 {
570         static in_addr_t (*inet_networkp)(const char *cp);
571         in_addr_t iret;
572  
573         BEFORE_ORIGINAL(inet_network, LIBC);
574  
575         iret = inet_networkp(cp);
576
577         AFTER_PACK_ORIGINAL_SOCK(API_ID_inet_network,
578                                  iret, 0, 0, FD_API_OTHER, "p", cp);
579
580         return iret;
581 }
582
583 char *inet_ntoa(struct in_addr in)
584 {
585         static char * (*inet_ntoap)(struct in_addr in);
586         char* sret;
587  
588         BEFORE_ORIGINAL(inet_ntoa, LIBC);
589  
590         sret = inet_ntoap(in);
591
592         AFTER_PACK_ORIGINAL_SOCK(API_ID_inet_ntoa, sret, 0, 0, FD_API_OTHER, "d", in.s_addr);
593  
594         return sret;
595 }
596
597 #if 0
598 struct in_addr inet_makeaddr(int net, int host)
599 {
600         static struct in_addr (*inet_makeaddrp)(int net, int host);
601         struct in_addr iret;
602  
603         BEFORE_ORIGINAL(inet_makeaddr, LIBC);
604  
605         iret = inet_makeaddrp(net,host);
606
607         AFTER_PACK_ORIGINAL_SOCK(API_ID_inet_makeaddr,
608                                  iret.s_addr, 0, 0, FD_API_OTHER,
609                                  "dd", net, host);
610
611         return iret;
612 }
613 #endif
614
615 in_addr_t inet_lnaof(struct in_addr in)
616 {
617         static in_addr_t (*inet_lnaofp)(struct in_addr in);
618         in_addr_t iret;
619  
620         BEFORE_ORIGINAL(inet_lnaof, LIBC);
621  
622         iret = inet_lnaofp(in);
623
624         AFTER_PACK_ORIGINAL_SOCK(API_ID_inet_lnaof,
625                                  iret, 0, 0, FD_API_OTHER, "d", in.s_addr);
626  
627         return iret;
628 }
629
630 in_addr_t inet_netof(struct in_addr in)
631 {
632         static in_addr_t (*inet_netofp)(struct in_addr in);
633         in_addr_t iret;
634  
635         BEFORE_ORIGINAL(inet_netof, LIBC);
636  
637         iret = inet_netofp(in);
638
639         AFTER_PACK_ORIGINAL_SOCK(API_ID_inet_netof,
640                                  iret, 0, 0, FD_API_OTHER, "d", in.s_addr);
641  
642         return iret;
643 }
644
645 const char *inet_ntop(int af, const void *src, char *dst, socklen_t size)
646 {
647         static const char* (*inet_ntopp)(int af, const void *src, char *dst, socklen_t size);
648         const char* cret;
649  
650         BEFORE_ORIGINAL(inet_ntop, LIBC);
651  
652         cret = inet_ntopp(af, src, dst, size);
653
654         AFTER_PACK_ORIGINAL_SOCK(API_ID_inet_ntop,
655                                  cret, size, 0, FD_API_OTHER,
656                                  "dppd", af, src, dst, size);
657  
658         return cret;
659 }
660
661 int inet_pton(int af, const char *src, void *dst)
662 {
663         static int (*inet_ptonp)(int af, const char *src, void *dst);
664  
665         BEFORE_ORIGINAL(inet_pton, LIBC);
666  
667         ret = inet_ptonp(af, src, dst);
668
669         AFTER_PACK_ORIGINAL_SOCK(API_ID_inet_pton,
670                                  ret, 0, 0, FD_API_OTHER, "%dpp", af, src, dst);
671  
672         return ret;
673 }
674
675 int getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res)
676 {
677         static int (*getaddrinfop)(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res);
678  
679         BEFORE_ORIGINAL_NOFILTER(getaddrinfo, LIBC);
680  
681         ret = getaddrinfop(node, service, hints, res);
682
683         AFTER_PACK_ORIGINAL_SOCK(API_ID_getaddrinfo,
684                                  ret, 0, 0, FD_API_OTHER, "pppp", node, service, hints, res);
685
686         return ret;
687 }
688
689 void freeaddrinfo(struct addrinfo *res)
690 {
691         static void (*freeaddrinfop)(struct addrinfo *res);
692
693         BEFORE_ORIGINAL_NOFILTER(freeaddrinfo, LIBC);
694  
695         freeaddrinfop(res);
696
697         AFTER_PACK_ORIGINAL_SOCK(API_ID_freeaddrinfo,
698                                  0, 0, 0, FD_API_OTHER, "p", res);
699 }
700
701 const char *gai_strerror(int errcode)
702 {
703         static const char * (*gai_strerrorp)(int errcode);
704         const char * cret;
705  
706         BEFORE_ORIGINAL(gai_strerror, LIBC);
707  
708         cret = gai_strerrorp(errcode);
709
710         AFTER_PACK_ORIGINAL_SOCK(API_ID_gai_strerror,
711                                  cret, 0, 0, FD_API_OTHER, "d", errcode);
712
713         return cret;
714 }
715
716 int gai_suspend(const struct gaicb* const list[], int nitems, const struct timespec *timeout)
717 {
718         static int (*gai_suspendp)(const struct gaicb* const list[], int nitems, const struct timespec *timeout);
719
720         BEFORE_ORIGINAL(gai_suspend, LIBC);
721  
722         ret = gai_suspendp(list,nitems,timeout);
723
724         AFTER_PACK_ORIGINAL_SOCK(API_ID_gai_suspend,
725                                  ret, 0, 0, FD_API_OTHER, "pdp", list, nitems, timeout);
726
727         return ret;
728 }
729
730 int gai_error(struct gaicb *req)
731 {
732         static int (*gai_errorp)(struct gaicb *req);
733  
734         BEFORE_ORIGINAL(gai_error, LIBC);
735  
736         ret = gai_errorp(req);
737
738         AFTER_PACK_ORIGINAL_SOCK(API_ID_gai_error,
739                                  ret, 0, 0, FD_API_OTHER, "p", req);
740  
741         return ret;
742 }
743
744 int gai_cancel(struct gaicb *req)
745 {
746         static int (*gai_cancelp)(struct gaicb *req);
747  
748         BEFORE_ORIGINAL(gai_cancel, LIBC);
749  
750         ret = gai_cancelp(req);
751
752         AFTER_PACK_ORIGINAL_SOCK(API_ID_gai_cancel,
753                                  ret, 0, 0, FD_API_OTHER, "p", req);
754  
755         return ret;
756 }
757
758 int getaddrinfo_a(int mode, struct gaicb *list[], int nitems, struct sigevent *sevp)
759 {
760         static int (*getaddrinfo_ap)(int mode, struct gaicb *list[], int nitems, struct sigevent *sevp);
761  
762         BEFORE_ORIGINAL(getaddrinfo_a, LIBC);
763  
764         ret = getaddrinfo_ap(mode, list,nitems, sevp);
765
766         AFTER_PACK_ORIGINAL_SOCK(API_ID_getaddrinfo_a,
767                                  ret, 0, 0, FD_API_OTHER, "dpdp", mode, list, nitems, sevp);
768  
769         return ret;
770 }
771 #endif
772
773 int getsockopt(int socket, int level, int option_name, void *option_value, socklen_t *option_len)
774 {
775         static int (*getsockoptp)(int socket, int level, int option_name, void *option_value, socklen_t *option_len);
776  
777         BEFORE_ORIGINAL(getsockopt, LIBC);
778  
779         ret = getsockoptp(socket, level, option_name, option_value, option_len);
780
781         AFTER_PACK_ORIGINAL_SOCK(API_ID_getsockopt,
782                                  ret, 0, socket, FD_API_OPTION, "dddpp",
783                                  socket, level, option_name, option_value, option_len);
784  
785         return ret;
786 }
787
788 int setsockopt(int socket, int level, int option_name, const void *option_value, socklen_t option_len)
789 {
790         static int (*setsockoptp)(int socket, int level, int option_name, const void *option_value, socklen_t option_len);
791  
792         BEFORE_ORIGINAL(setsockopt, LIBC);
793
794         ret = setsockoptp(socket, level, option_name, option_value, option_len);
795
796         AFTER_PACK_ORIGINAL_SOCK(API_ID_setsockopt,
797                                  ret, option_len, socket, FD_API_OPTION, "dddpd",
798                                  socket, level, option_name, option_value, option_len);
799
800         return ret;
801 }
802
803 #if 1
804 int getsockname(int sockfd, struct sockaddr *addr, socklen_t *addrlen )
805 {
806         static int (*getsocknamep)(int sockfd, struct sockaddr *addr, socklen_t *addrlen );
807  
808         BEFORE_ORIGINAL(getsockname, LIBC);
809  
810         ret = getsocknamep(sockfd, addr, addrlen);
811
812         AFTER_PACK_ORIGINAL_SOCK(API_ID_getsockname,
813                                  ret, 0, sockfd, FD_API_OTHER, "dpp", sockfd, addr, addrlen);
814
815         return ret;
816 }
817
818 int getdomainname(char *name, size_t len)
819 {
820         static int (*getdomainnamep)(char *name, size_t len);
821  
822         BEFORE_ORIGINAL(getdomainname, LIBC);
823  
824         ret = getdomainnamep(name, len);
825
826         AFTER_PACK_ORIGINAL_SOCK(API_ID_getdomainname,
827                                  ret, len, 0, FD_API_OTHER, "px", name, len);
828
829         return ret;
830 }
831
832 int setdomainname(const char *name, size_t len)
833 {
834         static int (*setdomainnamep)(const char *name, size_t len);
835  
836         BEFORE_ORIGINAL(setdomainname, LIBC);
837  
838         ret = setdomainnamep(name, len);
839
840         AFTER_PACK_ORIGINAL_SOCK(API_ID_setdomainname,
841                                  ret, len, 0, FD_API_OTHER, "px", name, len);
842  
843         return ret;
844 }
845
846 int gethostname(char *name, size_t len)
847 {
848         static int (*gethostnamep)(char *name, size_t len);
849  
850         BEFORE_ORIGINAL(gethostname, LIBC);
851  
852         ret = gethostnamep(name, len);
853
854         AFTER_PACK_ORIGINAL_SOCK(API_ID_gethostname,
855                                  ret, len, 0, FD_API_OTHER, "px", name, len);
856  
857         return ret;
858 }
859
860 int sethostname(const char *name, size_t len)
861 {
862         static int (*sethostnamep)(const char *name, size_t len);
863  
864         BEFORE_ORIGINAL(sethostname, LIBC);
865  
866         ret = sethostnamep(name, len);
867
868         AFTER_PACK_ORIGINAL_SOCK(API_ID_sethostname,
869                                  ret, len, 0, FD_API_OTHER, "px", name, len);
870  
871         return ret;
872 }
873
874 int getpeername(int s, struct sockaddr *addr, socklen_t *len)
875 {
876         static int (*getpeernamep)(int s, struct sockaddr *addr, socklen_t *len);
877
878         BEFORE_ORIGINAL(getpeername, LIBC);
879  
880         ret = getpeernamep(s, addr, len);
881
882         AFTER_PACK_ORIGINAL_SOCK(API_ID_getpeername,
883                                  ret, 0, s, FD_API_OTHER, "dpp", s, addr, len);
884  
885         return ret;
886 }
887
888 #if GCC_VERSION < 40800
889 int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, socklen_t hostlen, char *serv, socklen_t servlen, unsigned int flags)
890 {
891         static int (*getnameinfop)(const struct sockaddr *sa, socklen_t salen, char *host, socklen_t hostlen, char *serv, socklen_t servlen, unsigned int flags);
892 #else 
893 int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags)
894 {
895         static int (*getnameinfop)(const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags);
896 #endif 
897         BEFORE_ORIGINAL(getnameinfo, LIBC);
898  
899         ret = getnameinfop(sa, salen,host, hostlen, serv, servlen, flags);
900
901         AFTER_PACK_ORIGINAL_SOCK(API_ID_getnameinfo,
902                                  ret, 0, 0, FD_API_OTHER, "pdpdpdd",
903                                  sa, salen, host, hostlen, serv, servlen, flags);
904  
905         return ret;
906 }
907
908 struct hostent *gethostbyname(const char *name)
909 {
910         static struct hostent * (*gethostbynamep)(const char *name);
911         struct hostent* pret;
912  
913         BEFORE_ORIGINAL(gethostbyname, LIBC);
914
915         pret = gethostbynamep(name);
916
917         AFTER_PACK_ORIGINAL_SOCK(API_ID_gethostbyname,
918                                  pret, 0, 0, FD_API_OTHER, "p", name);
919
920         return pret;
921 }
922
923 struct hostent *gethostbyaddr(const void *addr, socklen_t len, int type)
924 {
925         static struct hostent * (*gethostbyaddrp)(const void *addr, socklen_t len, int type);
926         struct hostent* pret;
927  
928         BEFORE_ORIGINAL(gethostbyaddr, LIBC);
929  
930         pret = gethostbyaddrp(addr, len, type);
931
932         AFTER_PACK_ORIGINAL_SOCK(API_ID_gethostbyaddr,
933                                  pret, 0, 0, FD_API_OTHER, "pdd", addr, len, type);
934
935         return pret;
936 }
937
938 void sethostent(int stayopen)
939 {
940         static void (*sethostentp)(int stayopen);
941
942         BEFORE_ORIGINAL(sethostent, LIBC);
943  
944         sethostentp(stayopen);
945
946         AFTER_PACK_ORIGINAL_SOCK(API_ID_sethostent,
947                                  0, 0, 0, FD_API_OTHER, "d", stayopen);
948 }
949
950 void endhostent(void)
951 {
952         static void (*endhostentp)(void);
953
954         BEFORE_ORIGINAL(endhostent, LIBC);
955
956         endhostentp();
957
958         AFTER_PACK_ORIGINAL_SOCK(API_ID_endhostent,
959                                  0, 0, 0, FD_API_OTHER, "", 0);
960 }
961
962 void herror(const char *s)
963 {
964         static void (*herrorp)(const char *s);
965
966         BEFORE_ORIGINAL(herror, LIBC);
967  
968         herrorp(s);
969
970         AFTER_PACK_ORIGINAL_SOCK(API_ID_herror,
971                                  0, 0, 0, FD_API_OTHER, "p", s);
972 }
973
974 const char *hstrerror(int err)
975 {
976         static const char* (*hstrerrorp)(int err);
977         const char* cret;
978  
979         BEFORE_ORIGINAL(hstrerror, LIBC);
980  
981         cret = hstrerrorp(err);
982
983         AFTER_PACK_ORIGINAL_SOCK(API_ID_hstrerror,
984                                  cret, 0, 0, FD_API_OTHER, "d", err);
985
986         return cret;
987 }
988
989 struct hostent *gethostent(void)
990 {
991         static struct hostent* (*gethostentp)(void);
992         struct hostent* pret;
993  
994         BEFORE_ORIGINAL(gethostent, LIBC);
995  
996         pret = gethostentp();
997
998         AFTER_PACK_ORIGINAL_SOCK(API_ID_gethostent,
999                                  pret, 0, 0, FD_API_OTHER, "", 0);
1000
1001         return pret;
1002 }
1003
1004 struct hostent *gethostbyname2(const char *name, int af)
1005 {
1006         static struct hostent * (*gethostbyname2p)(const char *name, int af);
1007         struct hostent* pret;
1008  
1009         BEFORE_ORIGINAL(gethostbyname2, LIBC);
1010  
1011         pret = gethostbyname2p(name, af);
1012
1013         AFTER_PACK_ORIGINAL_SOCK(API_ID_gethostbyname2,
1014                                  pret, 0, 0, FD_API_OTHER, "pd", name, af);
1015
1016         return pret;
1017 }
1018
1019 int gethostent_r(struct hostent *rret, char *buf, size_t buflen, struct hostent **result, int *h_errnop)
1020 {
1021         static int (*gethostent_rp)(struct hostent *rret, char *buf, size_t buflen, struct hostent **result, int *h_errnop);
1022  
1023         BEFORE_ORIGINAL(gethostent_r, LIBC);
1024         
1025         ret = gethostent_rp(rret, buf, buflen, result, h_errnop);
1026
1027         AFTER_PACK_ORIGINAL_SOCK(API_ID_gethostent_r,
1028                                  ret, 0, 0, FD_API_OTHER, "ppxpp",
1029                                  rret, buf, buflen, result, h_errnop);
1030
1031         return ret;
1032 }
1033
1034 int gethostbyaddr_r(const void *addr, socklen_t len, int type, struct hostent *rret, char *buf, size_t buflen, struct hostent **result, int *h_errnop)
1035 {
1036         static int (*gethostbyaddr_rp)(const void *addr, socklen_t len, int type, struct hostent *rret, char *buf, size_t buflen, struct hostent **result, int *h_errnop);
1037
1038         BEFORE_ORIGINAL(gethostbyaddr_r, LIBC);
1039
1040         ret = gethostbyaddr_rp(addr, len, type, rret, buf, buflen, result, h_errnop);
1041
1042         AFTER_PACK_ORIGINAL_SOCK(API_ID_gethostbyaddr_r,
1043                                  ret, 0, 0, FD_API_OTHER, "pddppxpp",
1044                                  addr, len, type, rret, buf, buflen, result, h_errnop);
1045
1046         return ret;
1047 }
1048
1049 int gethostbyname_r(const char *name, struct hostent *rret, char *buf, size_t buflen, struct hostent **result, int *h_errnop)
1050 {
1051         static int (*gethostbyname_rp)(const char *name, struct hostent *rret, char *buf, size_t buflen, struct hostent **result, int *h_errnop);
1052  
1053         BEFORE_ORIGINAL(gethostbyname_r, LIBC);
1054
1055         ret = gethostbyname_rp(name, rret, buf, buflen, result, h_errnop);
1056
1057         AFTER_PACK_ORIGINAL_SOCK(API_ID_gethostbyname_r,
1058                                  ret, 0, 0, FD_API_OTHER, "pppxpp",
1059                                  name, rret, buf, buflen, result, h_errnop);
1060
1061         return ret;
1062 }
1063
1064 int gethostbyname2_r(const char *name, int af, struct hostent *rret, char *buf, size_t buflen, struct hostent **result, int *h_errnop)
1065 {
1066         static int (*gethostbyname2_rp)(const char *name, int af, struct hostent *rret, char *buf, size_t buflen, struct hostent **result, int *h_errnop);
1067  
1068         BEFORE_ORIGINAL(gethostbyname2_r, LIBC);
1069  
1070         ret = gethostbyname2_rp(name, af, rret, buf, buflen, result, h_errnop);
1071
1072         AFTER_PACK_ORIGINAL_SOCK(API_ID_gethostbyname2_r,
1073                                  ret, 0, 0, FD_API_OTHER, "pdppxpp",
1074                                  name, af, rret, buf, buflen, result, h_errnop);
1075  
1076         return ret;
1077 }
1078
1079 struct servent *getservbyname(const char *name, const char *proto)
1080 {
1081         static struct servent * (*getservbynamep)(const char *name, const char *proto);
1082         struct servent* pret;
1083  
1084         BEFORE_ORIGINAL(getservbyname, LIBC);
1085  
1086         pret = getservbynamep(name, proto);
1087
1088         AFTER_PACK_ORIGINAL_SOCK(API_ID_getservbyname,
1089                                  pret, 0, 0, FD_API_OTHER, "pp", name, proto);
1090
1091         return pret;
1092 }
1093
1094 void setservent(int stayopen)
1095 {
1096         static void (*setserventp)(int stayopen);
1097
1098         BEFORE_ORIGINAL(setservent, LIBC);
1099  
1100         setserventp(stayopen);
1101
1102         AFTER_PACK_ORIGINAL_SOCK(API_ID_setservent,
1103                                  0, 0, 0, FD_API_OTHER, "d", stayopen);
1104 }
1105
1106 void endservent(void)
1107 {
1108         static void (*endserventp)(void);
1109
1110         BEFORE_ORIGINAL(endservent, LIBC);
1111  
1112         endserventp();
1113
1114         AFTER_PACK_ORIGINAL_SOCK(API_ID_endservent,
1115                                  0, 0, 0, FD_API_OTHER, "", 0);
1116 }
1117
1118 struct servent *getservent(void)
1119 {
1120         static struct servent * (*getserventp)(void);
1121         struct servent* pret;
1122  
1123         BEFORE_ORIGINAL(getservent, LIBC);
1124  
1125         pret = getserventp();
1126
1127         AFTER_PACK_ORIGINAL_SOCK(API_ID_getservent,
1128                                  pret, 0, 0, FD_API_OTHER, "", 0);
1129
1130         return pret;
1131 }
1132
1133 struct servent *getservbyport(int port, const char *proto)
1134 {
1135         static struct servent * (*getservbyportp)(int port, const char *proto);
1136         struct servent* pret;
1137  
1138         BEFORE_ORIGINAL(getservbyport, LIBC);
1139  
1140         pret = getservbyportp(port, proto);
1141
1142         AFTER_PACK_ORIGINAL_SOCK(API_ID_getservbyport,
1143                                  pret, 0, 0, FD_API_OTHER, "dp", port, proto);
1144
1145         return pret;
1146 }
1147
1148 int getservent_r(struct servent *result_buf, char *buf, size_t buflen, struct servent **result)
1149 {
1150         static int (*getservent_rp)(struct servent *result_buf, char *buf, size_t buflen, struct servent **result);
1151  
1152         BEFORE_ORIGINAL(getservent_r, LIBC);
1153  
1154         ret = getservent_rp(result_buf, buf, buflen, result);
1155
1156         AFTER_PACK_ORIGINAL_SOCK(API_ID_getservent_r,
1157                                  ret, 0, 0, FD_API_OTHER, "ppxp",
1158                                  result_buf, buf, buflen, result);
1159
1160         return ret;
1161 }
1162
1163 int getservbyname_r(const char *name, const char *proto, struct servent *result_buf, char *buf, size_t buflen, struct servent **result)
1164 {
1165         static int (*getservbyname_rp)(const char *name, const char *proto, struct servent *result_buf, char *buf, size_t buflen, struct servent **result);
1166  
1167         BEFORE_ORIGINAL(getservbyname_r, LIBC);
1168  
1169         ret = getservbyname_rp(name, proto, result_buf, buf, buflen, result);
1170
1171         AFTER_PACK_ORIGINAL_SOCK(API_ID_getservbyname_r,
1172                                  ret, 0, 0, FD_API_OTHER, "ppppxp",
1173                                  name, proto, result_buf, buf, buflen, result);
1174
1175         return ret;
1176 }
1177
1178 int getservbyport_r(int port, const char *proto, struct servent *result_buf, char *buf, size_t buflen, struct servent **result)
1179 {
1180         static int (*getservbyport_rp)(int port, const char *proto, struct servent *result_buf, char *buf, size_t buflen, struct servent **result);
1181  
1182         BEFORE_ORIGINAL(getservbyport_r, LIBC);
1183  
1184         ret = getservbyport_rp(port, proto, result_buf, buf, buflen, result);
1185
1186         AFTER_PACK_ORIGINAL_SOCK(API_ID_getservbyport_r,
1187                                  ret, 0, 0, FD_API_OTHER, "dpppxp",
1188                                  port, proto, result_buf, buf, buflen, result);
1189
1190         return ret;
1191 }
1192
1193 struct netent* getnetent(void)
1194 {
1195         static struct netent * (*getnetentp)(void);
1196         struct netent* pret;
1197  
1198         BEFORE_ORIGINAL(getnetent, LIBC);
1199  
1200         pret = getnetentp();
1201
1202         AFTER_PACK_ORIGINAL_SOCK(API_ID_getnetent,
1203                                  pret, 0, 0, FD_API_OTHER, "", 0);
1204
1205         return pret;
1206 }
1207
1208 struct netent *getnetbyname(const char *name)
1209 {
1210         static struct netent * (*getnetbynamep)(const char *name);
1211         struct netent* pret;
1212  
1213         BEFORE_ORIGINAL(getnetbyname, LIBC);
1214  
1215         pret = getnetbynamep(name);
1216
1217         AFTER_PACK_ORIGINAL_SOCK(API_ID_getnetbyname,
1218                                  pret, 0, 0, FD_API_OTHER, "p", name);
1219  
1220         return pret;
1221 }
1222
1223 struct netent *getnetbyaddr(uint32_t net, int type)
1224 {
1225         static struct netent * (*getnetbyaddrp)(uint32_t net, int type);
1226         struct netent * pret;
1227  
1228         BEFORE_ORIGINAL(getnetbyaddr, LIBC);
1229
1230         pret = getnetbyaddrp(net, type);
1231
1232         AFTER_PACK_ORIGINAL_SOCK(API_ID_getnetbyaddr,
1233                                  pret, 0, 0, FD_API_OTHER, "dd", net, type);
1234
1235         return pret;
1236 }
1237
1238 void setnetent(int stayopen)
1239 {
1240         static void (*setnetentp)(int stayopen);
1241
1242         BEFORE_ORIGINAL(setnetent, LIBC);
1243  
1244         setnetentp(stayopen);
1245
1246         AFTER_PACK_ORIGINAL_SOCK(API_ID_setnetent,
1247                                  0, 0, 0, FD_API_OTHER, "d", stayopen);
1248 }
1249
1250 void endnetent(void)
1251 {
1252         static void (*endnetentp)(void);
1253
1254         BEFORE_ORIGINAL(endnetent, LIBC);
1255  
1256         endnetentp();
1257
1258         AFTER_PACK_ORIGINAL_SOCK(API_ID_endnetent,
1259                                  0, 0, 0, FD_API_OTHER, "", 0);
1260 }
1261
1262 int getnetent_r(struct netent *result_buf, char *buf, size_t buflen, struct netent **result, int *h_errnop)
1263 {
1264         static int (*getnetent_rp)(struct netent *result_buf, char *buf, size_t buflen, struct netent **result, int *h_errnop);
1265  
1266         BEFORE_ORIGINAL(getnetent_r, LIBC);
1267  
1268         ret = getnetent_rp(result_buf, buf, buflen, result, h_errnop);
1269
1270         AFTER_PACK_ORIGINAL_SOCK(API_ID_getnetent_r,
1271                                  ret, 0, 0, FD_API_OTHER, "ppxpp",
1272                                  result_buf, buf, buflen, result, h_errnop);
1273
1274         return ret;
1275 }
1276
1277 int getnetbyname_r(const char *name, struct netent *result_buf, char *buf, size_t buflen, struct netent **result, int *h_errnop)
1278 {
1279         static int (*getnetbyname_rp)(const char *name, struct netent *result_buf, char *buf, size_t buflen, struct netent **result, int *h_errnop);
1280  
1281         BEFORE_ORIGINAL(getnetbyname_r, LIBC);
1282  
1283         ret = getnetbyname_rp(name,result_buf, buf, buflen, result, h_errnop);
1284
1285         AFTER_PACK_ORIGINAL_SOCK(API_ID_getnetbyname_r,
1286                                  ret, 0, 0, FD_API_OTHER, "pppxpp",
1287                                  name, result_buf, buf, buflen, result, h_errnop);
1288
1289         return ret;
1290 }
1291
1292 int getnetbyaddr_r(uint32_t net, int type, struct netent *result_buf, char *buf, size_t buflen, struct netent **result, int *h_errnop)
1293 {
1294         static int (*getnetbyaddr_rp)(uint32_t net, int type, struct netent *result_buf, char *buf, size_t buflen, struct netent **result, int *h_errnop);
1295  
1296         BEFORE_ORIGINAL(getnetbyaddr_r, LIBC);
1297  
1298         ret = getnetbyaddr_rp(net, type, result_buf, buf, buflen, result, h_errnop);
1299
1300         AFTER_PACK_ORIGINAL_SOCK(API_ID_getnetbyaddr_r,
1301                                  ret, 0, 0, FD_API_OTHER, "ddppxpp",
1302                                  net, type, result_buf, buf, buflen, result, h_errnop);
1303
1304         return ret;
1305 }
1306
1307 struct protoent *getprotoent(void)
1308 {
1309         static struct protoent * (*getprotoentp)(void);
1310         struct protoent * pret;
1311  
1312         BEFORE_ORIGINAL(getprotoent, LIBC);
1313  
1314         pret = getprotoentp();
1315
1316         AFTER_PACK_ORIGINAL_SOCK(API_ID_getprotoent,
1317                                  pret, 0, 0, FD_API_OTHER, "", 0);
1318  
1319         return pret;
1320 }
1321
1322 struct protoent *getprotobyname(const char *name)
1323 {
1324         static struct protoent * (*getprotobynamep)(const char *name);
1325         struct protoent * pret;
1326  
1327         BEFORE_ORIGINAL(getprotobyname, LIBC);
1328  
1329         pret = getprotobynamep(name);
1330
1331         AFTER_PACK_ORIGINAL_SOCK(API_ID_getprotobyname,
1332                                  pret, 0, 0, FD_API_OTHER, "p", name);
1333
1334         return pret;
1335 }
1336
1337 struct protoent *getprotobynumber(int proto)
1338 {
1339         static struct protoent * (*getprotobynumberp)(int proto);
1340         struct protoent * pret;
1341  
1342         BEFORE_ORIGINAL(getprotobynumber, LIBC);
1343  
1344         pret = getprotobynumberp(proto);
1345
1346         AFTER_PACK_ORIGINAL_SOCK(API_ID_getprotobynumber,
1347                                  pret, 0, 0, FD_API_OTHER, "d", proto);
1348
1349         return pret;
1350 }
1351
1352 void setprotoent(int stayopen)
1353 {
1354         static void (*setprotoentp)(int stayopen);
1355
1356         BEFORE_ORIGINAL(setprotoent, LIBC);
1357  
1358         setprotoentp(stayopen);
1359
1360         AFTER_PACK_ORIGINAL_SOCK(API_ID_setprotoent,
1361                                  0, 0, 0, FD_API_OTHER, "d", stayopen);
1362 }
1363
1364 void endprotoent(void)
1365 {
1366         static void (*endprotoentp)(void);
1367
1368         BEFORE_ORIGINAL(endprotoent, LIBC);
1369  
1370         endprotoentp();
1371  
1372         AFTER_PACK_ORIGINAL_SOCK(API_ID_endprotoent,
1373                                  0, 0, 0, FD_API_OTHER, "", 0);
1374 }
1375
1376 int getprotoent_r(struct protoent *result_buf, char *buf, size_t buflen, struct protoent **result)
1377 {
1378         static int (*getprotoent_rp)(struct protoent *result_buf, char *buf, size_t buflen, struct protoent **result);
1379  
1380         BEFORE_ORIGINAL(getprotoent_r, LIBC);
1381  
1382         ret = getprotoent_rp(result_buf, buf, buflen, result);
1383
1384         AFTER_PACK_ORIGINAL_SOCK(API_ID_getprotoent_r,
1385                                  ret, 0, 0, FD_API_OTHER, "ppxp",
1386                                  result_buf, buf, buflen, result);
1387
1388         return ret;
1389 }
1390
1391 int getprotobyname_r(const char *name, struct protoent *result_buf, char *buf, size_t buflen, struct protoent **result)
1392 {
1393         static int (*getprotobyname_rp)(const char *name, struct protoent *result_buf, char *buf, size_t buflen, struct protoent **result);
1394  
1395         BEFORE_ORIGINAL(getprotobyname_r, LIBC);
1396  
1397         ret = getprotobyname_rp(name, result_buf, buf, buflen, result);
1398
1399         AFTER_PACK_ORIGINAL_SOCK(API_ID_getprotobyname_r,
1400                                  ret, 0, 0, FD_API_OTHER, "pppxp",
1401                                  name, result_buf, buf, buflen, result);
1402
1403         return ret;
1404 }
1405
1406 int getprotobynumber_r(int proto, struct protoent *result_buf, char *buf, size_t buflen, struct protoent **result)
1407 {
1408         static int (*getprotobynumber_rp)(int proto, struct protoent *result_buf, char *buf, size_t buflen, struct protoent **result);
1409  
1410         BEFORE_ORIGINAL(getprotobynumber_r, LIBC);
1411  
1412         ret = getprotobynumber_rp(proto, result_buf, buf, buflen, result);
1413
1414         AFTER_PACK_ORIGINAL_SOCK(API_ID_getprotobynumber_r,
1415                                  ret, 0, 0, FD_API_OTHER, "dppxp",
1416                                  proto, result_buf, buf, buflen, result);
1417
1418         return ret;
1419 }
1420
1421 unsigned int if_nametoindex (__const char *__ifname)
1422 {
1423         static unsigned int (*if_nametoindexp)(__const char *__ifname);
1424         unsigned int uret;
1425  
1426         BEFORE_ORIGINAL(if_nametoindex, LIBC);
1427  
1428         uret = if_nametoindexp(__ifname);
1429
1430         AFTER_PACK_ORIGINAL_SOCK(API_ID_if_nametoindex,
1431                                  uret, 0, 0, FD_API_OTHER, "p", __ifname);
1432  
1433         return uret;
1434 }
1435
1436 char *if_indextoname (unsigned int __ifindex, char *__ifname)
1437 {
1438         static char * (*if_indextonamep)(unsigned int __ifindex, char *__ifname);
1439         char * cret;
1440         
1441         BEFORE_ORIGINAL(if_indextoname, LIBC);
1442  
1443         cret = if_indextonamep(__ifindex, __ifname);
1444
1445         AFTER_PACK_ORIGINAL_SOCK(API_ID_if_indextoname,
1446                                  cret, 0, 0, FD_API_OTHER,
1447                                  "dp", __ifindex, __ifname);
1448
1449         return cret;
1450 }
1451
1452 struct if_nameindex *if_nameindex (void)
1453 {
1454         static struct if_nameindex * (*if_nameindexp)(void);
1455         struct if_nameindex * pret;
1456  
1457         BEFORE_ORIGINAL_NOFILTER(if_nameindex, LIBC);
1458         
1459         pret = if_nameindexp();
1460
1461         AFTER_PACK_ORIGINAL_SOCK(API_ID_if_nameindex,
1462                                  pret, 0, 0, FD_API_OTHER, "", 0);
1463
1464         return pret;
1465 }
1466
1467 void if_freenameindex (struct if_nameindex *__ptr)
1468 {
1469         static void (*if_freenameindexp)(struct if_nameindex *__ptr);
1470
1471         BEFORE_ORIGINAL_NOFILTER(if_freenameindex, LIBC);
1472  
1473         if_freenameindexp(__ptr);
1474  
1475         AFTER_PACK_ORIGINAL_SOCK(API_ID_if_freenameindex,
1476                                  0, 0, 0, FD_API_OTHER, "p", __ptr);
1477 }
1478
1479 int getifaddrs(struct ifaddrs **ifap)
1480 {
1481         static int (*getifaddrsp)(struct ifaddrs **ifap);
1482  
1483         BEFORE_ORIGINAL_NOFILTER(getifaddrs, LIBC);
1484  
1485         ret = getifaddrsp(ifap);
1486
1487         AFTER_PACK_ORIGINAL_SOCK(API_ID_getifaddrs,
1488                                  ret, 0, 0, FD_API_OTHER, "p", ifap);
1489  
1490         return ret;
1491 }
1492
1493 void freeifaddrs(struct ifaddrs *ifa)
1494 {
1495         static void (*freeifaddrsp)(struct ifaddrs *ifa);
1496
1497         BEFORE_ORIGINAL_NOFILTER(freeifaddrs, LIBC);
1498  
1499         freeifaddrsp(ifa);
1500  
1501         AFTER_PACK_ORIGINAL_SOCK(API_ID_freeifaddrs,
1502                                  0, 0, 0, FD_API_OTHER, "p", ifa);
1503 }
1504
1505 #if 0
1506 int poll(struct pollfd *ufds, unsigned int nfds, int timeout)
1507 {
1508         static int (*pollp)(struct pollfd *ufds, unsigned int nfds, int timeout);
1509  
1510         BEFORE_ORIGINAL(poll, LIBC);
1511  
1512         ret = pollp(ufds, nfds, timeout);
1513
1514         AFTER_PACK_ORIGINAL_SOCK(ret, timeout, 0, FD_API_OTHER, "pdd", ufds, nfds, timeout);
1515
1516         return ret;
1517 }
1518
1519 int ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout_ts, const sigset_t *sigmask)
1520 {
1521         static int (*ppollp)(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout_ts, const sigset_t *sigmask);
1522  
1523         BEFORE_ORIGINAL(ppoll, LIBC);
1524  
1525         ret = ppollp(fds, nfds, timeout_ts, sigmask);
1526
1527         AFTER_PACK_ORIGINAL_SOCK(ret, 0, 0, FD_API_OTHER, "pxpp",
1528                         fds, nfds, timeout_ts, sigmask);
1529
1530         return ret;
1531 }
1532 #endif
1533
1534 #endif