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