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 8339861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:59:57+00:00 2026-06-09T04:59:57+00:00

I will like to read network packets from a single board computer into a

  • 0

I will like to read network packets from a single board computer into a database(mysql to be precise), code to communicate between the single board computer and mysql is to be written in c. Please I need your help in getting useful links to some materials online, as I have been trying to seek for useful information but not yielding any result yet. Thank you for your understanding.

  • 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-09T04:59:59+00:00Added an answer on June 9, 2026 at 4:59 am

    You need to install first libmysqlclient-dev package (I assume you’re under linux) on your system, then you can modify this code to meet your need:

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <errno.h>
    #include <mysql/mysql.h>
    
    #define BUFFER_SIZE 1024    // Increase this buffer if yoy want
    
    /* This function is used for the database connection */
    MYSQL * my_mysql_connection(const char *server, const char *db, const char *user, const char *pwd)
    {
        MYSQL *myh;
    
        /* Some initialisation */ 
        if (NULL == (myh = mysql_init(NULL)))
        {
            fprintf(stdeee, "Fails to allocate memory for MYSQL!\n");
    
            exit (EXIT_FAILURE);
        }
    
        /* Connect to the database. */
        if (NULL == mysql_real_connect (myh, server, user, pwd, db, 0, NULL, 0))
        {
            fprintf(stderr, "%s", mysql_error(myh));
            free (myh);
    
            return NULL;
        }
    
        return myh;
     }
    
    /* This function is used to perform a query */ 
    int my_mysql_query(MYSQL *myh, const char *query)
    {
        /* Do the query request */
        if (0 != mysql_query(myh, query))
        {
            fprintf(stderr, "FAIL to perform the query : '%s' %s\n", query, mysql_error(myh));
    
            exit (EXIT_FAILURE);
        }
    
        return 0;
    }
    
    /*
     * Suppose that your table students_table has this fields : student_number, student_name, 
     * student_address, student_phone
     */
    /* This function is used to get and process the result of the query */
    void my_mysql_process_query_result(MYSQL * myh)
    {
        int num_fields;
        int i;
        MYSQL_RES *query_result;
        MYSQL_FIELD *field;
        MYSQL_ROW row;
        char  *buffer;
    
        buffer = (char *) calloc(BUFFER_SIZE, sizeof(char));
    
        /* Select all students present in the students_table */
        if (my_mysql_query(myh, "SELECT student_number, student_name, student_address, student_phone FROM students_table"))
        {
            exit (EXIT_FAILURE);
        }
        query_result = mysql_store_result (myh);
    
        /* Retreive the number of rows and fields */
        field = mysql_fetch_fields(query_result);
        num_fields = mysql_num_fields(query_result);
    
        /* construct the buffer containing each row */
        while ((row = mysql_fetch_row (query_result))) 
        {
            /* Init our buffer with fields sperated by ";", modify if you need, it's just an example */
            memset(buffer, '\0', sizeof*buffer);
    
            for (i = 0; i < num_fields - 1; i++)
            {
                strncat(buffer, row[i], strlen(row[i]) + 1);
                strncat(buffer, ";", 2);            
            }   
            strncat(buffer, row[i], strlen(row[i]) + 1);
            strncat(buffer, "\n", 2);
            // You can process your buffer (row) here
            process_student_row(buffer);
        }
        free(buffer);
    
        mysql_free_result (query_result);
    }
    

    Don’t forget to link to the mysqlclient library : -lmysqlclient.

    Edit:

    You can install libmysqlclient-dev (http://packages.debian.org/squeeze/libmysqlclient-dev) on debian like this:

    sudo apt-get update
    sudo apt-get install libmysqlclient-dev
    

    You can compile your program like this:

    gcc -Wall my_msql_program.c -o my_mysql_program -lmysqlclient
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to write a function which will read values from a text
I'd like to read the contents of a .csv file from a website, into
I'm creating xml-like mark-up language using System.Xml.XmTextWriter that will be read by a third
I'm projecting a monitoring client in Java which will read information from /proc .
Suppose I have no network card installed on my computer, and I would like
My goal is to VPN from my iPhone into my home network for iTunes
I implemented social-network-like notification, using long-polling with nodeJs database, I'm using redis and cassandra
A question to windows network programming experts. When I use pseudo-code like this: reconnect:
Imagine following situation: There is a distributed key/value database stored on computer network. One
I will like to use the objdump command on cygwin. I get the exception:

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.