< type="text/javascript"> < type="text/javascript" src=\'#\'" //pagead2.googlesyndication.com/pagead/show_ads.js"> |
int status, sock, mode;
/* Create a new stream (TCP) socket */
sock = socket( AF_INET, SOCK_STREAM, 0 );
...status = send( sock, buffer, buflen, MSG_DONTWAIT );
if (status == -1)
{ /* send failed */
printf( "send failed: %s\n",
?
strerror(errno) );
}
else
{ /* send succeeded -- or did it? */}
|
int sock, status;
sock = socket( AF_INET, SOCK_STREAM, 0 );
...status = read( sock, buffer, buflen );
if (status > 0)
{ /* Data read from the socket */}
else if (status == -1)
{
/* Error, check errno, take action... */
}
else if (status == 0)
{
/* Peer closed the socket, finish the close */
close( sock );
/* Further processing... */
}
|
int sock, ret, on;struct sockaddr_in servaddr;
/* Create a new stream (TCP) socket */
sock = socket( AF_INET, SOCK_STREAM, 0 ):
/* Enable address reuse */
on = 1;
ret = setsockopt( sock, SOL_SOCKET, SO_REUSEADDR,
&on, sizeof(on) );
/* Allow connections to port 8080 from any available interface
*/
memset( &servaddr, 0, sizeof(servaddr) );
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl( INADDR_ANY );
servaddr.sin_port = htons( 45000 );
/* Bind to the address (interface/port) */
ret = bind( sock, (struct sockaddr *)&servaddr, sizeof(servaddr) );
|
View all TCP sockets currently active$ netstat
--tcpView all UDP sockets$ netstat
--udpView all TCP sockets in the listening state$ netstat
--listeningView the multicast group membership information$ netstat
--groupsDisplay the list of masqueraded connections$ netstat
--masqueradeView statistics for each protocol$ netstat
--statistics
|
Display all traffic on the eth0 interface for
the local host$ tcpdump -l -i eth0Show all traffic
on the network coming from or going
to host plato$ tcpdump host platoShow all HTTP traffic
for host camus$ tcpdump host camus and (port http)View
traffic coming from or going
to TCP port 45000 on the local host$ tcpdump tcp port 45000
|
< type="text/javascript">
< type="text/javascript" src=\'#\'" //pagead2.googlesyndication.com/pagead/show_ads.js">