1 / 14

Network Programming CSC- 341

Network Programming CSC- 341. Instructor: Junaid Tariq, Lecturer, Department of Computer Science. 12. Lecture. Network Programming. Part 2 Sockets Introduction Chapter 3. Byte Manipulation Functions. #include <strings.h> void bzero ( void *dest , size_t nbytes );

lobo
Télécharger la présentation

Network Programming CSC- 341

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Network ProgrammingCSC- 341 Instructor: Junaid Tariq, Lecturer, Department of Computer Science

  2. 12 Lecture Network Programming

  3. Part 2 Sockets IntroductionChapter 3

  4. Byte Manipulation Functions • #include <strings.h> void bzero(void *dest, size_t nbytes); /* sets the specified no of bytes to zero */ void bcopy(const void *src, void *dest, size_t nbytes); /* byte by byte copy from source to destination */ int bcmp(const void *ptr1, const void *ptr2, size_t nbytes); /* return 0 if equal, nonzero if unequal */

  5. BZERO

  6. BCOPY

  7. BCMP

  8. Byte Manipulation Functions Cont. • #include <string.h> void *memset(void *dest, int c, size_t len); /* sets specified no of bytes to ‘c’ */ void *memcpy(void *dest, const void *src, size_t nbytes); /* byte string copy from source to destination but undefined if source and destination buffers overlap*/ int memcmp(const void *ptr1, const void *ptr2, size_t nbytes); /* ptr1 < ptr2 : less than 0 (for first unequal bytes) ptr1 > ptr2 : greater than 0 (for first unequal bytes) ptr1 = ptr2 : than 0 Each bytes is considered as unsigned char */

  9. 3.6 inet_aton,inet_addr, inet_ntoa functions • Convert internet address between ASCII string and network byte ordered binary values(as stored in socket address structure) • Used for IPv4 addresses conversion • For both IPv4 and IPv6 we have : inet_pton , inet_ntop

  10. #include<arpa/inet.h> For ASCII to network binary: int inet_aton(const char *strptr, struct in_addr *addrptr); /* return : 1 if successful,0 on error */ For ASCII to network binary: in_addr_t inet_addr(const char *strptr); /* return : 32bit binary network byte ordered IPv4 address; INADDR_NONE (32 one-bits) if error */ For network binary to ASCII: char *inet_ntoa(struct in_addr inaddr); /*return pointer to dotted-decimal string*/

  11. ATON & NTOA

  12. 3.7 inet_pton,inet_ntopfunction • Both IPv4,IPv6 address conversion • p : presentation(string) n : numeric(binary) • #include<arpa/inet.h> int inet_pton(int family, const char *strptr, void *addrptr); /* return: 1 if OK, 0 if input not a valid presentation format, -1 if family not supported */ const char *inet_ntop(int family, const void *addrptr, char *strpt, size_t len); /* return : pointer to result if OK, NULL if length allocated for string is smaller then required size, 16 for IPv4 dotted decimal and 46 for IPv6 hex*/ /* len : size of the destination string allocated by the caller*/

  13. PTON & NTOP

More Related