title: C - getaddrinfo returns "Servname not supported for ai_socktype"
body: <p>So, after I got this error, I've been looking for an answer in here, almost everyone had a difficult way to fix this error but no one explained why this error occurs at all, so I don't find this question to be exactly duplicate.  </p>
  
  <p>I wrote a TCP socket in C and I used "getaddrinfo" function to make the socket work with hostnames, well it worked perfectly! you can find my codes on <a href="https://github.com/proph8/Sockets/tree/master/TCPEcho" rel="nofollow noreferrer">github</a>.</p>
  
  <p>but when I tried to create a <a href="https://github.com/proph8/Sockets/tree/master/UDPEcho" rel="nofollow noreferrer">UDP socket</a> by "getaddrinfo" I got this error:<br>
  <strong>Servname not supported for ai_socktype</strong>  </p>
  
  <p><em>client.c</em></p>
  
  <pre><code>const char *host = argv[1];
  const char *service = argv[2];
  const char *string = argv[3];
  
  struct addrinfo addrCriteria;
  memset(&amp;addrCriteria, 0, sizeof(addrCriteria));
  addrCriteria.ai_family = AF_UNSPEC;
  addrCriteria.ai_socktype = SOCK_DGRAM;
  addrCriteria.ai_protocol = IPPROTO_UDP;
  
  struct addrinfo *servAddr;
  int ret = getaddrinfo(host, service, &amp;addrCriteria, &amp;servAddr);
  if(ret != 0)
      sysError(gai_strerror(ret));
  </code></pre>
  
  <p>I realized that when I give "service" a numeric input like 8080, no errors would return but when I use a string as service name like "tproxy" which points to port/8081, 'gai_strerror' returns mentioned error.</p>
  
  <p>Obviously, gai_strerror says: "service names not supported for 'SOCK_DGRAM' socket types", but why? I mean the exact reason for "getaddrinfo" not supporting name services over UDP sockets?<br>
  Is there any other way to use service names with UDP sockets instead of port numbers? how?</p>