#include <stdio.h>
u
^X7m7x _jY2}
#include <stdlib.h>
sYu*]@#U:h&epZ2qV#include <string.h>
iL|#n5l'Q4H#include <sys/un.h>
Linux伊甸园论坛;ia
s+Z:[#C ^
#include <sys/types.h>
www.linuxeden.comD'WL9^\4W8I
#include <sys/socket.h>
xZ"yp2u/Aowww.linuxeden.com#include <netinet/in.h>
8{ Nn8j SoV3?i;Owww.linuxeden.com#include <unistd.h>
Rz
pxpK-`Ae
j#include <errno.h>
b&ip*R%H
W'Z4k`&y#@5uchar *
O!][R,r e],u
sock_ntop(const struct sockaddr *sa, socklen_t salen)
t ?0MU*y)Fj
{
%}`.`.Q(iyC1Y:H0b
char portstr[8];
mTf&S+GH
static char str[128]; /* Unix domain is largest */
t6r!R?'H.\{
www.linuxeden.com:I.[C8w7O-rk
D
switch (sa->sa_family) {
3F{6nYK
o&{#D
case AF_INET: {
%Yx{_9zS
struct sockaddr_in *sin = (struct sockaddr_in *) sa;
J$z&\$l
lc,M D8dwww.linuxeden.com
@P^\b0I if ( inet_ntop(AF_INET, &sin->sin_addr, str, sizeof(str)) == NULL)
8N
R%IECfV9c Dy
return(NULL);
nA1C'z ]-c if (ntohs(sin->sin_port) != 0) {
3{
^#@)gA snprintf(portstr, sizeof(portstr), ":%d", ntohs(sin->sin_port));
-p1m
O#G t@'`,VLinux伊甸园论坛 strcat(str, portstr);
1Rd:_P"V#QLinux伊甸园论坛 }
8Od0c~)iG%?
return(str);
mf`u+aQ
}
2Mq6Lu4saI default:
7T O%tG s;X
A1V snprintf(str, sizeof(str), "sock_ntop: unknown AF_xxx: %d, len %d",
!V X)fq a{"w"@xS5F
| sa->sa_family, salen);
4xEO3m gtc
URf return(str);
www.linuxeden.com
f,n5sG1}+LwO_
}
BcJ0z%s$fhw return (NULL);
kX1N2c"^k&[
} /** end sock_ntop **/
9I8@z%Pps8tb
(i{{/h9b0G+Zm这个函数,我用gcc -c 编译时提示:
%W9`.G)@u*n,ELinux伊甸园论坛sockaddr.c: 在函数 ‘sock_ntop’ 中:
|?YK)Cedn
sockaddr.c:340: 警告:比较指针和整数
YN4| PE8a!T+it
就是这句: ( inet_ntop(AF_INET, &sin->sin_addr, str, sizeof(str)) == NULL)
$I/TE(Ak.da$@ XLinux伊甸园论坛这是UNP上的代码,但是如果我给改成:
4[+fW3P%J0z ( ! inet_ntop(AF_INET, &sin->sin_addr, str, sizeof(str)))
kJ]*x
w ~&c#N_
就没有警告了,
(J9Lb\B\4v"`1x
这是不是GCC的BUG?
p'h5D!J{:z?&P5dU3f_B为何inet_ntop的返回值类型被认为是整型??