Experimental studies have shown the ubiquity of altruistic behavior in human societies. The social structure is a fundamental ingredient to understand the degree of altruism displayed by the members of a society, in contrast to individual-based features, like for example age or gender, which have been shown not to be relevant to determine the level of altruistic behavior. We explore an evolutionary model aiming to delve how altruistic behavior is affected by social structure. We investigate the dynamics of interacting individuals playing the Ultimatum Game with their neighbors given by a social network of interaction. We show that a population self-organizes in a critical state where the degree of altruism depends on the topology characterizing the social structure. In general, individuals offering large shares but in turn accepting large shares, are removed from the population. In heterogeneous social networks, individuals offering intermediate shares are strongly selected in contrast to random homogeneous networks where a broad range of offers, below a critical one, is similarly present in the population.