哪位高手知道getpeername这个函数的源代码
谁知道getpeername这个函数的源代码?
谁知道getpeername这个函数的源代码?
分享一下。
------解决方案--------------------
谁知道getpeername这个函数的源代码?
分享一下。
------解决方案--------------------
00001 #include <errno.h>
00002 #include <stdio.h>
00003 #include <string.h>
00004 #include <sys/ioctl.h>
00005 #include <sys/socket.h>
00006 #include <netinet/in.h>
00007
00008 #include <net/gen/in.h>
00009 #include <net/gen/tcp.h>
00010 #include <net/gen/tcp_io.h>
00011 #include <net/gen/udp.h>
00012
00013 #define DEBUG 0
00014
00015 static int _tcp_getpeername(int socket, struct sockaddr *_RESTRICT address,
00016 socklen_t *_RESTRICT address_len, nwio_tcpconf_t *tcpconfp);
00017
00018 int getpeername(int socket, struct sockaddr *_RESTRICT address,
00019 socklen_t *_RESTRICT address_len)
00020 {
00021 int r;
00022 nwio_tcpconf_t tcpconf;
00023
00024 r= ioctl(socket, NWIOGTCPCONF, &tcpconf);
00025 if (r != -1
------解决方案--------------------
errno != ENOTTY)
00026 {
00027 if (r == -1)
00028 {
00029 /* Bad file descriptor */
00030 return -1;
00031 }
00032 return _tcp_getpeername(socket, address, address_len,
00033 &tcpconf);
00034 }
00035
00036 #if DEBUG
00037 fprintf(stderr, "getpeername: not implemented for fd %d\n", socket);
00038 #endif
00039 errno= ENOSYS;
00040 return -1;
00041 }
00042
00043 static int _tcp_getpeername(int socket, struct sockaddr *_RESTRICT address,
00044 socklen_t *_RESTRICT address_len, nwio_tcpconf_t *tcpconfp)
00045 {
00046 socklen_t len;