Пример #1
0
struct servent * WINSOCKAPI getservbyname(const char * name,
                                          const char * proto)
{
 struct servent *ps = &RgServEnt[0];
 BOOL fFoundOnce = FALSE; // flag to short-circuit search through rest of db

 // Make lowercase versions for comparisons
 // truncate to 1 char longer than any value in table
 char szNameLC[CCH_MAX_SERV+2];
 strcpyLC(szNameLC, name, CCH_MAX_SERV+1);
 char szProtoLC[CCH_MAX_PROTO+2];
 if (NULL != proto)
  strcpyLC(szProtoLC, proto, CCH_MAX_PROTO+1);

 while (NULL != ps->s_name)
 {
  if (!strcmp(szNameLC, ps->s_name))
  {
   fFoundOnce = TRUE;
   if (NULL == proto || !strcmp(szProtoLC, ps->s_proto))
   {
    ServEntReturn = *ps;
    ServEntReturn.s_port = htons(ps->s_port);
    return &ServEntReturn;
   }
  }
  else if (fFoundOnce)
   break;
  ++ps;
 } return NULL;
}
Пример #2
0
struct servent * WINSOCKAPI getservbyport(int port, const char * proto)
{

 port = ntohs((unsigned short)port); // arrives in network byte order
 struct servent *ps = &RgServEnt[0];
 BOOL fFoundOnce = FALSE; // flag to short-circuit search through rest of db

 // Make a lowercase version for comparison
 // truncate to 1 char longer than any value in table
 char szProtoLC[CCH_MAX_PROTO+2];
 if (NULL != proto)
  strcpyLC(szProtoLC, proto, CCH_MAX_PROTO+1);

 while (NULL != ps->s_name)
 {
  if (port == ps->s_port)
  {
   fFoundOnce = TRUE;
   if (NULL == proto || !strcmp(szProtoLC, ps->s_proto))
   {
    ServEntReturn = *ps;
    ServEntReturn.s_port = htons(ps->s_port);
    return &ServEntReturn;
   }
  }
  else if (fFoundOnce)
   break;
  ++ps;
 } return NULL;
}