Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6673039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:34:51+00:00 2026-05-26T03:34:51+00:00

I am following the example given in An Introductory 4.4BSD Interprocess Communication Tutorial where

  • 0

I am following the example given in An Introductory 4.4BSD Interprocess Communication Tutorial where it is the process of showing how to communicate using datagrams in the internet domain. In examples, 6a and 6b , 6a sets the port and the hostname

name.sin_addr.s_addr = INADDR_ANY;
name.sin_port = 0;

From what I understand, INADDR_ANY is a wildcard value allowing the socket to receive from anywhere. But, I cannot send from anywhere and explicitly set the hostname in 6b

hp = gethostbyname(argv[1]);

So what hostname would be valid here? When I have tried

program6b localhost 0

But that says it cannot assign the requested address (I have used other addresses and the same message). 6a says that “Socket has port #0” though this means it listens on all ports right? In any case I tried setting the post manually so that “Socket has port #53790”. Netstat shows it is listening

udp4 0 0 *.53790 .

And using the command

program6b localhost 53790

I get a response that the data has been received from the socket which reads. So, I partially understand what is going on, but I would like to know how the example should work for port#0.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:34:51+00:00Added an answer on May 26, 2026 at 3:34 am

    Port 0, both UDP and TCP cannot be normally used. They are indicated in the sockets API bind to request that the Operating System assign an arbitrary free port to the application. It is usually done with client code, that doesn’t care about the specific port used. Server code, in the other hand, usually specifies a known port.

    About the INADDR_ANY, when doing the local bind, it means:

    • Listen at all network interfaces, if the socket is listening.
    • Let the OS choose the appropriate network interface for sending data.

    If instead you indicate an address, it should be an address of your machine, and refers to the network interface that owns that address. Then:

    • If the socket is listening: it will listen only in that network interface.
    • If the socket sends data, it will consider only that network interface.

    As a note: you cannot listen to every port at the same time, unless you use some kind of raw socket. But not with UDP or TCP.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following example (using JUnit with Hamcrest matchers): Map<String, Class<? extends Serializable>> expected
I have a problem using docstrings with decorators. Given the following example: def decorator(f):
Given the following example: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.Serialization.Formatters.Binary;
Given the following example, why do I have to explicitly use the statement b->A::DoSomething()
Given the following example data: Users +--------------------------------------------------+ | ID | First Name | Last
Given a sorted vector with a number of values, as in the following example:
Given the following simple example: List<string> list = new List<string>() { One, Two, Three,
Given the following HTML example... <div id='div1'>div one</div> <div id='div2'>div two</div> ...I found that
Given a group of files with the following naming convention: datetime_restofname.txt an example of
Given the URL (single line): http://test.example.com/dir/subdir/file.html How can I extract the following parts using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.