Basic Hash programming

Basic Hash programming Hash.h =====  /**************************************************************************  *   A simple hash table implementation for strings.  ***************************************************************************/ #ifndef HASH_H #define HASH_H  typedef struct hash_t {   struct hash_node_t **bucket;      /* array of hash nodes */   int size;                         /* size of the array */   int entries;                      /* number of entries in table */   int downshift;                    /* shift count, used in hash function […]

Basic Unix Programming

Basic Unix Programming Signal Handler —————– /* Sample program to handle signals */ #include <signal.h>#include <stdio.h> void * myhandler(int myint){   printf(“nHey, I got signalled!!nn”);   exit(0);} int main(){   signal( SIGINT, (void *)  myhandler );    while(1) {    printf(“I am in an infinite loop!n”);    sleep(1);   }}     /* Skeletal Shell for simple command */ main (argc, […]

Basic Socket programming

Basic Socket programming /* Sample UDP client */   #include <sys/socket.h> #include <netinet/in.h> #include <stdio.h>   int main(int argc, char**argv) {    int sockfd,n;    struct sockaddr_in servaddr,cliaddr;    char sendline[1000];    char recvline[1000];      if (argc != 2)    {       printf(“usage:  udpcli <IP address>n”);       exit(1);    }      […]

Pthreads

PthreadsExample of multithreaded programming in C without mutual exclusion/locks #include <pthread.h> #include <stdio.h> int count = 0; void* run_thread() {    pthread_t thread_id = pthread_self();    printf(“Thread %u: Current value of count = %dn”, thread_id, count);    printf(“Thread %u incrementing count …n”);    count++;    sleep(1);    printf(“Value of count after incremented by thread %u […]

How to write the code for audio loopback in linux

How to write the code for  audio loopback in linux /* Standard Linux headers */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/ioctl.h> #include <fcntl.h> #include <signal.h> #include <getopt.h> #include <pthread.h> #include <errno.h>   #include <linux/soundcard.h>   #define FAILURE            -1 /* The number of channels of the audio codec */ #define NUM_CHANNELS           2   /* The […]

Packet decoder

Packet decoder #include <stdlib.h> // exit#include <unistd.h> // exit#include <arpa/inet.h> // inet_ntoa#include <netinet/if_ether.h> // ETHER_ADDR_LEN struct ip_header { // Internet Protocol header    #if BYTE_ORDER == LITTLE_ENDIAN    u_int ip_hl:4, ip_v:4;    #endif    #if BYTE_ORDER == BIG_ENDIAN    u_int ip_v:4, ip_hl:4;    #endif    u_char  ip_tos;            // type of service    u_short ip_len;            // total length     u_short ip_id;             // identification    […]

How to write the code for displaying mixer setting in linux

How to write the code for displaying mixer setting in linux /*  * mixer_info.c  * Example program to display mixer settings  */   #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <sys/ioctl.h> #include <fcntl.h> #include <linux/soundcard.h>   /* utility function for printing status */ void yes_no(int condition) {   condition ? printf(”  yes      “) : printf(”  […]

How to write configure script

1.Introduction To start using the GNU configure and build system with your software package, you must write three files, and you must run some tools to manually generate additional files. 2.Write configure.in   You must first write the file `configure.in’. This is an autoconf input file, and the autoconf manual describes in detail what this […]

How to write the code for audio loopback in linux

Programming /dev/dsp (Obsolute,But latest oss still support the old versions) /dev/dsp is the digital sampling and digital recording device, and probably the most important for multimedia applications. Writing to the device accesses the D/A converter to produce sound. Reading the device activates the A/D converter for sound recording and analysis. The name DSP comes from […]

Thread synchronization

Thread synchronization As we know, to run threads, we need to schedule them. In order to run them effectively, they need to be synchronized. Suppose one thread creates a brush and then creates several threads that share the brush and draw with it. The first thread must not destroy the brush until the other threads […]