#include <sys/socket.h>
const char * getIpProtocolId( int sock) {
int proto;
socklen_t proto_len = sizeof ( proto) ;
int res = getsockopt( sock,SOL_SOCKET,SO_TYPE,
& proto,& proto_len) ;
if ( res == 0 ) switch ( proto) {
case SOCK_STREAM: return "tcp" ;
case SOCK_DGRAM: return "udp" ;
default : break ;
}
return "unknown" ;
}
I2luY2x1ZGUgPHN5cy9zb2NrZXQuaD4KCmNvbnN0IGNoYXIqIGdldElwUHJvdG9jb2xJZChpbnQgc29jayl7CiAgICBpbnQgcHJvdG87CiAgICBzb2NrbGVuX3QgcHJvdG9fbGVuID0gc2l6ZW9mKHByb3RvKTsKICAgIGludCByZXMgPSBnZXRzb2Nrb3B0KHNvY2ssU09MX1NPQ0tFVCxTT19UWVBFLAogICAgICAgICAgICAmcHJvdG8sJnByb3RvX2xlbik7CgogICAgaWYgKCByZXMgPT0gMCApIHN3aXRjaChwcm90byl7CiAgICAgICAgY2FzZSBTT0NLX1NUUkVBTTogcmV0dXJuICJ0Y3AiOwogICAgICAgIGNhc2UgU09DS19ER1JBTTogIHJldHVybiAidWRwIjsKICAgICAgICBkZWZhdWx0OiBicmVhazsKICAgIH0KCiAgICByZXR1cm4gInVua25vd24iOwp9Cgo=