XPCGetProtocol::XPCGetProtocol(int _iProtocol) { #ifdef UNIX cIteratorFlag = 0; #endif #ifdef __linux // Retrieves the protocol structure by number char buf[1024]; getprotobynumber_r(_iProtocol,&protocol, buf, sizeof(buf), &protocolPtr); //protocolPtr = getprotobynumber_r(_iProtocol);//thread safe fix suggested by Mark Moseley #else // Retrieves the protocol structure by number protocolPtr = getprotobynumber(_iProtocol); #endif if (protocolPtr == NULL) { XPCException exceptObject("Could Not Get Protocol By Number"); throw exceptObject; return; } }
struct protoent * getprotobynumber(int proto_num) { struct protoent *result; __initbuf(); getprotobynumber_r(proto_num, &proto, static_aliases, SBUFSIZE, &result); return result; }
int main () { struct protoent result_buf; struct protoent *result; char buf[BUFSIZE]; getprotobyname_r("", &result_buf, buf, BUFSIZE, &result); getprotobynumber_r("", &result_buf, buf, BUFSIZE, &result); return 104; }
struct protoent * getprotobynumber(int proto) { struct protoent *p; mutex_lock(&_protoent_mutex); p = getprotobynumber_r(proto, &_protoent_data.proto, &_protoent_data); mutex_unlock(&_protoent_mutex); return (p); }
struct protoent * getprotobynumber(int num) { extern struct protoent_data _protoent_data; static struct protoent proto; if (getprotobynumber_r(num, &proto, &_protoent_data) != 0) return (NULL); return (&proto); }
struct protoent * getprotobynumber(int proto) { struct protodata *pd; struct protoent *rval; if ((pd = __protodata_init()) == NULL) return (NULL); if (getprotobynumber_r(proto, &pd->proto, pd->data, sizeof(pd->data), &rval) != 0) return (NULL); return (rval); }
/* * call-seq: * Proto.getprotobynumber(num) * * Given a protocol number, returns the corresponding string, or nil if not * found. * * Examples: * * Net::Proto.getprotobynumber(6) # => "tcp" * Net::Proto.getprotobynumber(999) # => nil */ static VALUE np_getprotobynumber(VALUE klass, VALUE v_proto_num){ struct protoent p; char buffer[BUF_SIZE]; VALUE v_proto_name = Qnil; setprotoent(0); if(getprotobynumber_r(NUM2INT(v_proto_num),&p,buffer,BUF_SIZE) != NULL) v_proto_name = rb_str_new2(p.p_name); endprotoent(); return v_proto_name; }
/* *********************************************************************** */ int NPSL_GetProtoByNumberBasic(int proto_number, NPSL_PROTOENT *proto_ent_ptr, void *proto_ent_buffer_ptr, unsigned int proto_ent_buffer_length, unsigned int *required_length, char *error_text) { int return_code = NPSL_SUCCESS; NPSL_PROTOENT *tmp_ent_ptr; if (required_length != NULL) *required_length = 0; if ((return_code = NPSL_CheckProtoEntParams(proto_ent_ptr, proto_ent_buffer_ptr, proto_ent_buffer_length, error_text)) != NPSL_SUCCESS) ; else { #if NPSL_HAS_GETPROTOBYPORT_R if ((tmp_ent_ptr = getprotobynumber_r(proto_number, proto_ent_ptr, proto_ent_buffer_ptr, ((int) proto_ent_buffer_length))) == NULL) { if (error_text != NULL) { sprintf(error_text, "%s '%s()' for protocol number '%d': ", "Unable to get protocol entry with", "getprotobynumber_r", proto_number); NPSL_AppendLastErrorString(0, NPSL_MAX_ERROR_TEXT, error_text); } return_code = NPSL_SUPP_MapLastError(); } #else if ((tmp_ent_ptr = getprotobynumber(proto_number)) == NULL) { if (error_text != NULL) { sprintf(error_text, "%s '%s()' for protocol number '%d': ", "Unable to get protocol entry with", "getprotobynumber", proto_number); NPSL_AppendLastErrorString(0, NPSL_MAX_ERROR_TEXT, error_text); } return_code = NPSL_SUPP_MapLastError(); } else return_code = NPSL_CopyProtoEntFlatBasic(tmp_ent_ptr, proto_ent_ptr, proto_ent_buffer_ptr, proto_ent_buffer_length, required_length, error_text); #endif // #if NPSL_HAS_GETPROTOBYPORT_R } return(return_code); }
explicit protocol_entry(int protocol) { char name_buf_[name_buffer_length]; entry_type result_buf_, *result_; int retval = getprotobynumber_r( protocol, &result_buf_, name_buf_, sizeof name_buf_, &result_ ); if (result_ == nullptr || retval != 0) throw_error(retval); store_entry_elem(result_buf_); }
struct protoent * getprotobynumber(int proto_num) { struct protoent *result; getprotobynumber_r(proto_num, &proto, static_aliases, sizeof(static_aliases), &result); return result; }