SlideServe
Menu
Préférences
© SlideServe · v2026

Network Programming - Byte Manipulation and Socket Introduction

evarner avatar
14 diapositives · 180 Views · Jan 04, 2020

Learn about byte manipulation functions like bzero, bcopy, and bcmp. Discover how to convert data between ASCII and network binary formats using inet_aton, inet_addr, and inet_ntoa functions in network programming.

Network Programming - Byte Manipulation and Socket Introduction - slide 1
01 / 14Network Programming - Byte Manipulation and Socket Introduction
1 / 17

Télécharger la présentation

Network Programming - Byte Manipulation and Socket Introduction
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  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