Docsity

Week 9 Topics: Socket Options, UDP, Name and Address Conversions, and DNS, Slides of Computer Programming

Partial preview of the text

Download Week 9 Topics: Socket Options, UDP, Name and Address Conversions, and DNS and more Slides Computer Programming in PDF only on Docsity!

Week 9 Topics

  • Socket options
    • getsockopt, setsockopt
    • fcntl
    • ioctl
  • Introduction to UDP
    • TCP vs UDP
    • UDP interface

Week 9 Topics ... continued

  • Name and address conversions
    • Domain name system
    • gethostbyname
    • gethostbyaddr
    • uname
    • gethostname
    • getservbyname
    • getservbyport

Domain name system

  • Mapping between names and addresses
    • xi.cs.fsu.edu <--> 128.186.121.
  • References
    • See http://www.internic.net/faqs/authoritative- dns.html for information on - DNS organization - Why they should be the sole authority!

Domain name system ... continued

  • Hierarchical naming scheme
    • Name space partitioned into subdomains
    • Top level of domains
      • .com, .edu, .gov, .org, .us, .ca, .in, etc
    • Each domain can have subdomains
  • Distributed delegation of naming authority
    • Each domain has the authority to allow names within that domain
    • Naming follows organization boundary not physical network boundary

Name servers

  • Name server
    • When a name server receives a DNS request, if the server is the authority for the name, it finds the resource record and replies
    • Otherwise it recursively asks the next level
      • Example: gethostbyname(“www.cs.yale.edu”) xi.cs.fsu.edu ---> cs.fsu.edu --> edu --> yale.edu -->cs.yale.edu -->yale.edu-->edu -->cs.fsu.edu-->xi.cs.fsu.edu
    • Optimizations
      • Replication and caching

gethostbyname

#include <netdb.h>

struct hostent *gethostbyname(const char *hostname) struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; };

  • This function queries A or AAAA records

uname and gethostbyname

  • Information on name, os, and hardware
  • #include <sys/utsname.h>

_int uname (struct utsname *name) struct utsname { char sysname[_UTS_NAMESIZE]; char nodename[_UTS_NODESIZE]; char release[_UTS_NAMESIZE]; char version[_UTS_NAMESIZE]; char machine[UTS_NAMESIZE]; }

  • See example2.c
  • gethostbyname can be used to get host name

getservbyname and getservbyport

  • Get service information
    • Not querying the DNS, but a system specific file, for example /etc/services #include <netdb.h> struct servent *getservbyname(const char *servname, const char protoname); struct servent getservbyport(int port, const charprotoname); struct servent { char s_name; char s_aliases; int s_port; char *s_proto; }
  • See example3.c and example4.c