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

  • SEARCH
  • Home
  • 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 8646127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:43:25+00:00 2026-06-12T12:43:25+00:00

To make a long story short, i am implementing a mix-net in C. To

  • 0

To make a long story short, i am implementing a mix-net in C. To do this i’m creating several individual daemons which listen on a section of TCP ports (say 31001-31008), receive data on those ports and put it into a buffer (say TCP port 31002 –> char *data[2]), and then eventually write the data out on another set of ports (say 51001-51008) to the next daemon in the list.

With that out of the way, here’s my confusion! I did a lot of reading on here and elsewhere and decided that the easiest way to accomplish this would be using libevent2. I basically am starting with this (at the bottom of the page): http://www.wangafu.net/~nickm/libevent-book/Ref8_listener.html … except i am opening 8 ports instead of 1.

QUESTION: I’ve read through the manual but i’m a little confused on how to determine which port the data came from. For example, if i receive data on port 31004, i want to know to write it into data[4].

I thought about creating a different callback for each port i open, but that gets ugly. Is there an easier way?

Here is some psuedo-code of what i am trying to accomplish, feel free to make suggestions! I also looked into doing this in something like python, but it seems like python has the same issues with events.

define baseport 31000
define numports 8

public char *data[numports];

callback:
    /* a connection was made */
    received_data = recv(blah)

    databin = port_received_on % baseport
    ////// How do i know what port it was received on? /////
    strncpy(data[databin], received_data, sizeof(data[databin]));

main:
    for (i = 1; i <= numports; i++)
            data[i] = malloc 

    struct event_base *base;
    //setup base event, etc.

    for (int i = 1; i <= numports; i++) {
            //setup localhost connection, open 8 ports
            sin.sin_port = htons(baseport + i);

    //configure listener with callback to "callback"
    }

    dispatch
  • 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-06-12T12:43:26+00:00Added an answer on June 12, 2026 at 12:43 pm

    You could use one callback for each port, but that callback is only acting as a proxy calling the real callback with the correct array index.

    It can even by somewhat automated with a macro:

    #define DEF_CALLBACK(idx)      \
        void callback_ ## idx()    \
        {                          \
            real_callback(idx);    \
        }
    
    void real_callback(int idx)
    {
        /* ... */
    }
    
    DEF_CALLBACK(1)
    DEF_CALLBACK(2)
    /* etc. */
    

    Now you have the real callback function real_callback as well as a set of functions named callback_1, callback_2, etc.

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

Sidebar

Related Questions

So to make a long story short. A professor asked this question in class
Okay so to make a long story short I am using this script in
To make a very long story short… This is in a large WPF project
To make a long story short... I'm building a web app in which the
To make a long story as short as possible (ignore this paragraph if you
So to make a long story short, I've been working on a web app
I using a web services to get the value, make the long story short.
Short story: I can't make precompiled headers work properly with gcc -c option. Long
To make a long story short, I'm having trouble getting a couple of Java
I'm going to make a long story short. It's been a while that I

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.