int recvfrom(int sockfd, void *buf, int len, unsigned int flags,
2
struct sockaddr *from, int *fromlen);
Copied!
一樣,它跟 recv() 很像,只是多了兩個欄位。from 是指向 local struct sockaddr_storage 的指標,這個資料結構包含了封包來源的 IP address 與 port。fromlen 是指向 local int 的指標,應該要初始化為 sizeof *from 或是 sizeof(struct sockaddr_storage)。當函式傳回時,fromlen 會包含實際上儲存於 from 中的位址長度。